<?php
/**
 * ProjektMan
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 *
 * @category   ProjektMan
 * @name       Menu.php
 * @license    LICENSE.txt     New BSD License
 */

/**
 * Table model for project
 *
 * @category   ProjektMan
 * @name       Projekt_Html_Menu
 * @license    LICENSE.txt     New BSD License
 */

class Projekt_Html_Menu
{

	private $_list;  //store the list object
	private static $_lang;

	/**
	 * Constructor is passed an AccessPageList object
	 *
	 * @param AccessPageList $list
	 * @param string $currentController
	 * @param string $currentAction
	 */
	public function __construct(Zend_Db_Table_Rowset $list, $currentPageId)
	{
		$this->_list = $list;
	}


	/**
	 * set the language array for the menu
	 *
	 * @param array $lang
	 */
	public static function setLang($lang){
		self::$_lang = $lang;
	}

	/**
	 * Render the list into html
	 *
	 * @return string
	 */
	public function render()
	{
		$toplevel = '<ul class="topnav">';
		$bottomlevel = '<ul class="bottomnav">';

		foreach($this->_list as $item){
			if($item->access_page_id == $currentPageId){
				$toplevel .= "<li class='active'><a href='/" . $item->controller . "/" . $item->action . "/'>" . self::$_lang[$item->controller][$item->action] . "</a></li>";
			}else if($item->isChild($currentPageId)){
				$bottomlevel .= "<li><a href='/" . $item->controller . "/" . $item->action . "/'>" . self::$_lang[$item->controller][$item->action] . "</a></li>";
			}else{
				$toplevel .= "<li><a href='/" . $item->controller . "/" . $item->action . "/'>" . self::$_lang[$item->controller][$item->action] . "</a></li>";
			}
		}
		$toplevel .= "</ul>";
		$bottomlevel .= "</ul>";

		return $toplevel . "\n" . $bottomlevel;
	}
}